﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.AspNetCore.Http;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Extentions;
using TrainingReminderSystem.Model;
using TrainingReminderSystem.Dal;
using System.Threading.Tasks;

namespace TrainingReminderSystem.Bll
{
    /// <summary>
    /// 机构 逻辑层
    /// </summary>
    public partial class ReferrerBll : PcLoginedBll
    {
        protected override AjaxResult<dynamic> ValidatePartial<T, TDbContext>(T tModel, bool isAdd, AjaxResult<dynamic> r, TDbContext tDb)
        {
            var model = tModel as Referrer;
            var db = tDb as DbEntities;
            if (!string.IsNullOrEmpty(model.Phone))
            {
                if (db.Referrer.Any(m => m.Phone == model.Phone && m.ReferrerID != model.ReferrerID))
                {
                    string err = string.Format(comLan["Exists"], $"{keyLan["Phone"]}[{model.Phone}]");
                    return AjaxResult<dynamic>.ErrorResult(err);
                }
            }
            return base.ValidatePartial(tModel, isAdd, r, tDb);
        }

        protected override AjaxResult<dynamic> DelValidatePartial<T, TDbContext>(T tDbModel, AjaxResult<dynamic> r, TDbContext tDb)
        {
            var model = tDbModel as Organization;
            var db = tDb as DbEntities;
            return base.DelValidatePartial(tDbModel, r, tDb);
        }
    }
}
